package com.lin.chapter34;

public class Invoker {
    public String exec(String commandStr){
        String result = "";
        CommandVo vo = new CommandVo(commandStr);
        if (CommandEnum.getNames().contains(vo.getCommandName())){
            String className = CommandEnum.valueOf(vo.getCommandName()).getValue();
            Command command;
            try {
                command = (Command) Class.forName(className).newInstance();
                result = command.execute(vo);
            }catch (Exception e){

            }
        }else {
            result = "无法执行命令，请检查命令格式";
        }
        return result;
    }
}
